#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int n, u, v, a[2000000], c[2000000][2], num[2000000][2];
vector<int> to[2000000];
void dfs1(int x, int fa) {
    int siz = to[x].size();
    for (int i = 0; i < siz; i++) {
        int v = to[x][i];
        if (v == fa) continue;
        dfs1(v, x);
        if (a[v] > num[x][0]) {
            c[x][0] = c[v][0];
        } else {
            if (a[v] > num[x][1]) {
                c[x][1] = c[v][0];
            } else {
                if (a[v] == num[x][1])
                    c[x][1] = min(c[v][0], c[x][1]);
            }
        }
        if (num[x][0] == num[x][1] && c[x][0] < c[x][1]) {
        }
    }
    c[x][0] += a[x];
    c[x][1] += a[x];
}
int main() {
    scanf("%d", &n);
    for (int i = 2; i <= n; i++) {
        scanf("%d", &v);
        to[i].push_back(v);
        to[v].push_back(i);
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d", a + i);
    }
    dfs1(1, 0);
    return 0;
}